package concurrent;

import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author Created by chenxin34 on 2020/3/9 下午5:36.
 */
public class BlockQueueTest {
    public static void main(String[] args) throws Exception{
        BlockingQueue<Integer> blockingQueue = new ArrayBlockingQueue<>(100);

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(15000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("add queue");
                System.out.println(new Date());
                blockingQueue.offer(100);
            }
        }).start();

        try {
            System.out.println("#1");
            System.out.println(new Date());
            final Integer poll = blockingQueue.poll(10, TimeUnit.SECONDS);
            System.out.println(new Date());
            System.out.println("poll "  + poll);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        Thread.sleep(100000);

    }
}
